package com.example.topicservice.service;

import com.example.commentservice.service.CommentService;
import com.example.commonapi.pojo.UAT;
import com.example.commonapi.pojo.Topic;
import com.example.commonapi.pojo.User;
import com.example.topicservice.dao.TopicDao;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Service(version = "${demo.service.version}")
public class TopicServiceImpl implements TopicService {
    @Autowired
    private TopicDao topicDao;
    @Reference(version = "${demo.service.version}")
    private CommentService commentService;

    public void setTopicDao(TopicDao topicDao) {
        this.topicDao = topicDao;
    }


    @Override
    public List<UAT> search(String word) {
        return topicDao.search(word);
    }

    @Override
    public Integer addTopicT(Topic topic) {
        return topicDao.addTopic(topic);
    }

    public int deleteTopic(Topic topic) {
        return topicDao.deleteTopic(topic);
    }

    public Integer deleteTopicById(int id) {
        commentService.deleteCommentByTopicId(id);
        return topicDao.deleteTopicById(id);
    }

    public Topic getTopicById(int id) {
        return topicDao.getTopicById(id);
    }

    public List<Topic> totalTopic() {
        return topicDao.totalTopic();
    }

    public List<Topic> getTopicByUserId(Integer userId) {
        return topicDao.getTopicByUserId(userId);
    }

    public List<UAT> getAllUAT() {
        return topicDao.getAllUAT();
    }

    public User getUserByTopicId(Integer topicId) {
        return topicDao.getUserByTopicId(topicId);
    }

    public void topicUpdate(Topic topic) {
        topicDao.topicUpdate(topic);
    }

    public void deleteTopicByUserId(Integer userId) {
        topicDao.deleteTopicByUserId(userId);
    }

    public List<UAT> getUATByUserId(Integer userId) {
        return topicDao.getUATByUserId(userId);
    }
}
